/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package AGMap;
import java.sql.*;

/**
 *
 * @author admin
 */
public class Database {

private Connection con;
private ResultSet results;

public Database(String driver)
{
 try {
      Class.forName(driver);
     }

 catch(Exception e){
     System.err.println("Erreur lors du chargement du driver:"+ e.getMessage());
     }

  try {
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/apigooglemap", "root", "mysql");
      }

 catch(SQLException e){
  System.err.println("echec d'ouverture:"+e.getMessage());
 }

}

public void Close()
{
 try {
        con.close();
    }
 catch(SQLException e){
  System.err.println("echec lors de la fermeture:"+e.getMessage());
 }
}

public ResultSet Execute(String sql)
{
 results = null;

 try {
         Statement stmt = con.createStatement();
         results = stmt.executeQuery(sql);
     }

 catch(SQLException e){
  System.err.println(e.getMessage());
 }
return results;
}

public void Update(String sql)
{
  try {
         Statement stmt = con.createStatement();
         stmt.executeUpdate(sql);
       }

 catch(SQLException e){
  System.err.println(e.getMessage());
 }
}

public void afficheResultat()
{
    try {
            while (results.next())
            {
                String colonne1 = results.getString(1);
                System.out.println("Nom:" + colonne1);
            }
        }

    catch(SQLException e){
     System.err.println(e.getMessage());
     }
}
}
